<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>添加产品</title>
    <script type="text/javascript">
      Ext.onReady(function(){
              var vendorId = <%= session[:vendor_id] %>;
              var newProductForm=new Ext.form.FormPanel({
                    width:600,
                    //labelAlign: 'top',
                    url:'/product/create',
                    buttonAlign:'center',
                    autoHeight:true,
                    fileUpload: true,
                    bodyStyle: 'padding:5px',
                    labelWidth:100,
                    waitMsgTarget: true,
                    frame: true,
                    items:[{
                           xtype:'hidden',
                           name:'id',
                           value:vendorId
                     },{
                          layout:'column',
                          items:[{
                              columnWidth:.5,
                              layout:'form',
                              labelAlign: 'left',
                              items:[{
                                  xtype:'textfield',
                                  fieldLabel: '产品名称',
                                  name: 'name',
                                  allowBlank:false,
                                  anchor:'90%'
                              },{
                                  xtype:'textfield',
                                  fieldLabel: '型号',
                                  name: 'model',
                                  allowBlank:false,
                                  anchor:'90%' 
                              },{
                                  xtype:'textfield',
                                  fieldLabel: '产品品牌',
                                  name: 'brand',
                                  allowBlank:false,
                                  anchor:'90%'
                              }]
                          },{
                              columnWidth:.5,
                              layout:'form',
                              labelAlign: 'left',
                              items:[{
                                  xtype:'textfield',
                                  fieldLabel: '生产单位',
                                  name:'manufacturer',
                                  allowBlank:false,
                                  anchor:'90%'
                              },{
                                  xtype:'textfield',
                                  fieldLabel: '规格',
                                  name: 'specification',
                                  allowBlank:false,
                                  anchor:'90%'
                              },{
                                  fieldLabel: '单价（元）',
                                  xtype:'numberfield',
                                  name: 'unit_price',
                                  allowBlank:false,
                                  anchor:'90%'
                              }]
                          }]
                     },{
                          layout:'column',
                          items:[{
                              columnWidth:1,
                              layout:'form',
                              labelAlign: 'top',
                              items:[{
                                  xtype: 'fileuploadfield',
                                  id: 'form-file',
                                  emptyText: '请选择产品图片....',
                                  fieldLabel: '上传产品图片(现只支持jpg gif和bmp格式图片，大小应在500K以下)',
                                  name: 'file',
                                  anchor:'95%',
                                  allowBlank:false,
                                  buttonText: '',
                                  buttonCfg: {
                                      iconCls: 'imageUploadItem'
                                  }
                              },{
                                  xtype:'textarea',
                                  fieldLabel: '主要技术指标',
                                  name: 'technology_data',
                                  allowBlank:false,
                                  height:100,
                                  anchor: '95%'
                              }]
                          }]
                     }],
                     buttons:[{
                        text:'确定',
                        handler: function(){
                            // check form value
                            if (newProductForm.form.isValid()) {
                              newProductForm.form.submit({
                                method: 'post',
                                waitMsg: '正在保存产品信息...',
                                success: function(result, response){
                                  if (response.result.info == "success") {
                                    //添加成功后，隐藏窗口，并刷新Grid
                                    newProductWin.destroy();
                                  }
                                  else {
                                    Ext.MessageBox.alert('消息', response.result.info);
                                  }
                                },
                                failure: function(result, response){
                                  Ext.MessageBox.alert('提示', result.responseText);
                                }
                              });
                            }
                            else {
                              Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                            }
                          }
                    },{
                        text:'取消',
                        handler:function(){
                            newProductWin.destroy();
                        }
                    }]
                });
          newProductForm.render('new_product_form');
      })
    </script>
  </head>
  <body>
     <div id="new_product_form"></div>
  </body>
</html>
